<template>
	<view>
		<u-notice-bar v-if="noticeState" mode="horizontal" :list="noticeList" :more-icon="true" @getMore="noticeClick"
			@click="noticeClick"></u-notice-bar>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				noticeState: false, // 滚动框显隐
				noticeList: []
			};
		},
		mounted() {
			this.getNotice(); // 获取公告信息
		},
		onShow() {
			this.getNotice(); // 获取公告信息
		},
		methods: {
			// 获取公告信息
			getNotice() {
				let params = {
					current: 1,
					size: 5
				};
				this.noticeState = false
				this.noticeList = []
				this.$http
					.post({
						url: '/sys/notice/page',
						data: JSON.stringify(params)
					})
					.then(res => {
						// console.log('公告列表--------', res);
						this.noticeState = true
						if (res.code == 200) {
							let noticeInfo = res.data.records;
							noticeInfo.forEach((res, index) => {
								this.noticeList.push(index + 1 + '. ' + res.noticeName + ' ');
							});
							this.noticeList[this.noticeList.length - 1] = this.noticeList[this.noticeList.length - 1] +
								'...更多公告请点击进入明细查看！';
						} else {
							this.$refs.uToast.show({
								title: '公告' + res.msg,
								type: 'error'
							});
						}
					});
			},
			// 点击公告进入公告列表页
			noticeClick() {
				this.$pageJump.navigateTo('/pages/common/notice/noticeList');
			}
		}
	};
</script>

<style lang="scss" scoped></style>